import request from "@/utils/request";
import type { SkuListModel, SkuModel, SkuPageListModel } from "./model/skuModel";

enum Api {
  // GET /admin/product/cancelSale/{skuId}
  CancelSale = '/admin/product/cancelSale',
  // GET /admin/product/onSale/{skuId}
  OnSale = '/admin/product/onSale',
  // DELETE /admin/product/deleteSku/{skuId}
  DeleteSku = '/admin/product/deleteSku',
  // GET /admin/product/findBySpuId/{spuId}
  GetSkuListBySpuId = '/admin/product/findBySpuId',
   // GET /admin/product/getSkuById/{skuId}
   GetSkuInfo = '/admin/product/getSkuById',
  // GET /admin/product/list/{page}/{limit}
  GetSkuPageList = '/admin/product/list',
  // POST /admin/product/saveSkuInfo
  SaveSkuInfo = '/admin/product/saveSkuInfo',
}


// 获取sku分页列表
export const getSkuPageListApi = (page: number, limit: number) => {
  return request.get<any, SkuPageListModel>(Api.GetSkuPageList + `/${page}/${limit}`)
}
// 保存sku
export const saveSkuInfoApi = (skuInfo: SkuModel) => {
  return request.post(Api.SaveSkuInfo, skuInfo)
}

// 获取sku详情
export const getSkuInfoApi = (skuId: number) => {
  return request.get<any, SkuModel>(Api.GetSkuInfo + `/${skuId}`)
}

// 下架
export const cancelSaleApi = (skuId: number) => {
  return request.get(Api.CancelSale + `/${skuId}`)
}

// 上架
export const onSaleApi = (skuId: number) => {
  return request.get(Api.OnSale + `/${skuId}`)
}

// 删除sku
export const deleteSkuApi = (skuId: number) => {
  return request.delete(Api.DeleteSku + `/${skuId}`)
}

// 获取指定spu下的所有sku的列表
export const getSkuListBySpuIdApi = (spuId: number) => {
  return request.get<any, SkuListModel>(Api.GetSkuListBySpuId + `/${spuId}`)
}

